//
//  MyAzkarCell.m
//  Azkar
//
//  Created by CPX on 2018/9/18.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "MyAzkarCell.h"

/**
 我的祈福Cell
 @author yzl
 */
@interface MyAzkarCell()

@property (nonatomic,strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *avatarImageV;
@property (nonatomic, strong) UILabel *titleL;
@property (nonatomic, strong) UILabel *timeL;
@property (nonatomic, strong) UILabel *contentL;
@property (nonatomic, strong) UIButton *deleteB;
@property (nonatomic, strong) UIButton *likeB;
@property (nonatomic, strong) UIButton *shareB;
@property (nonatomic, strong) UIButton *msgB;

@end

@implementation MyAzkarCell

- (void)setBlessModel:(BlessModel *)blessModel{
    _blessModel = blessModel;
    
    [self.avatarImageV sd_setImageWithURL:[NSURL URLWithString:blessModel.avatar] placeholderImage:[UIImage imageNamed:@"no_photo"]];
//    self.titleL.text = blessModel.uname;
    NSString *time = [DateHelper dateStrFromTimeStamp:blessModel.create_date dateFormat:@"dd/MM HH:mm"];
    self.timeL.text = time;
    self.contentL.text = blessModel.content;
    [self.shareB setTitle:blessModel.cnt_shared forState:UIControlStateNormal];
    [self.msgB setTitle:blessModel.cnt_comment forState:UIControlStateNormal];
    
    if (blessModel.like) {
        [self.likeB setBackgroundColor:UIColorHex(#EFEFEF)];
        [self.likeB setImage:Image(@"dua_ic_s") forState:UIControlStateNormal];
        [self.likeB setTitle:[NSString stringWithFormat:@"%@ %@",blessModel.cnt_like,TLString(@"Has Duas")] forState:UIControlStateNormal];
        [self.likeB setTitleColor:UIColorHex(#929292) forState:UIControlStateNormal];
    }
    else{
        [self.likeB setBackgroundColor:UIColorHex(#2B9958)];
        [self.likeB setImage:Image(@"dua_ic") forState:UIControlStateNormal];
        [self.likeB setTitle:[NSString stringWithFormat:@"%@ %@",blessModel.cnt_like,TLString(@"greeting_cards_azkar_Duas_for_this")] forState:UIControlStateNormal];
        
        [self.likeB setTitleColor:UIColorHex(#ffffff) forState:UIControlStateNormal];
    }
    self.titleL.text = blessModel.uname.length?blessModel.uname:TLString(@"greeting_cards_Anonymously");
    if ([[LanguageManager defaultManager].appLanguage isEqualToString:@"ar"]) {
        self.timeL.text = self.timeL.text.arabicString;
    }
}

- (UIView*)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.cornerRadius = 5;
        _bgView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_bgView];
        self.contentView.backgroundColor = UIColorHex(#F6F6F6);
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.top.mas_equalTo(12);
            make.trailing.mas_equalTo(-12);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _bgView;
}

- (UIImageView*)avatarImageV{
    if (!_avatarImageV) {
        _avatarImageV = [UIImageView new];
        _avatarImageV.layer.masksToBounds = YES;
        _avatarImageV.layer.cornerRadius = 17;
        [self.bgView addSubview:_avatarImageV];
        [_avatarImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(34);
            make.top.mas_equalTo(12);
            make.leading.mas_equalTo(12);
        }];
    }
    return _avatarImageV;
}

- (UILabel*)titleL{
    if (!_titleL) {
        _titleL = [UILabel new];
        _titleL.font = [UIFont systemFontOfSize:13];
        _titleL.textColor = UIColorHex(#002812);
        [self.bgView addSubview:_titleL];
        [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.avatarImageV.mas_trailing).offset(8);
            make.trailing.mas_equalTo(-25);
            make.top.mas_equalTo(13.5);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _titleL;
}

- (UILabel*)timeL{
    if (!_timeL) {
        _timeL = [UILabel new];
        _timeL.font = [UIFont systemFontOfSize:11];
        _timeL.textColor = UIColorHex(#929292);
        [self.bgView addSubview:_timeL];
        [_timeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.avatarImageV.mas_trailing).offset(8);
            make.trailing.mas_equalTo(-25);
            make.top.mas_equalTo(self.titleL.mas_bottom).offset(3);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _timeL;
}

- (UILabel*)contentL{
    if (!_contentL) {
        _contentL = [UILabel new];
        _contentL.numberOfLines = 2;
        _contentL.font = [UIFont systemFontOfSize:15];
        _contentL.textColor = UIColorHex(#002812);
        [self.bgView addSubview:_contentL];
        [_contentL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.avatarImageV);
            make.trailing.mas_equalTo(-25);
            make.top.mas_equalTo(self.avatarImageV.mas_bottom).offset(12.5);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _contentL;
}

- (UIButton*)likeB{
    if (!_likeB) {
        _likeB = [UIButton buttonWithType:UIButtonTypeCustom];
        [_likeB setContentEdgeInsets:UIEdgeInsetsMake(0, 7.5, 0, 5.5)];
        _likeB.imageEdgeInsets = UIEdgeInsetsMake(0, -5.5, 0, 0);
        _likeB.layer.cornerRadius = 12;
        _likeB.layer.masksToBounds = YES;
        _likeB.titleLabel.font = [UIFont systemFontOfSize:10];
        [self.bgView addSubview:_likeB];
        [_likeB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(12);
            make.top.mas_equalTo(self.contentL.mas_bottom).offset(24);
            make.height.mas_equalTo(24);
            make.bottom.mas_equalTo(-16.5);
        }];
    }
    return _likeB;
}

- (UIButton*)shareB{
    if (!_shareB) {
        _shareB = [UIButton buttonWithType:UIButtonTypeCustom];
        _shareB.titleLabel.font = [UIFont systemFontOfSize:13];
        [_shareB setContentEdgeInsets:UIEdgeInsetsMake(0, 2.5, 0, 0)];
        _shareB.imageEdgeInsets = UIEdgeInsetsMake(0, -2.5, 0, 0);
        [_shareB setTitleColor:UIColorHex(#6F6F6F) forState:UIControlStateNormal];
        [_shareB setImage:[UIImage RTL_ImageWithName:@"share_gray_ic"] forState:UIControlStateNormal];
        [self.bgView addSubview:_shareB];
        [_shareB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.likeB);
            make.trailing.mas_equalTo(self.msgB.mas_leading).offset(-40);
            make.height.mas_equalTo(20);
            make.width.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _shareB;
}

- (UIButton*)msgB{
    if (!_msgB) {
        _msgB = [UIButton buttonWithType:UIButtonTypeCustom];
        _msgB.titleLabel.font = [UIFont systemFontOfSize:13];
        [_msgB setContentEdgeInsets:UIEdgeInsetsMake(0, 2.5, 0, 0)];
        _msgB.imageEdgeInsets = UIEdgeInsetsMake(0, -2.5, 0, 0);
        [_msgB setTitleColor:UIColorHex(#6F6F6F) forState:UIControlStateNormal];
        [_msgB setImage:[UIImage RTL_ImageWithName:@"comment_gray_ic"] forState:UIControlStateNormal];
        [self.bgView addSubview:_msgB];
        [_msgB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.likeB);
            make.trailing.mas_equalTo(-24);
            make.height.mas_equalTo(20);
            make.width.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _msgB;
}

@end
